<?php 
	@session_start();
	include("../connect/connect_mysql.php");
	$id = $_GET['id'];
	$page_id = $_GET['page'];
	
// 	$str = mysql_fetch_full_result_array($rs);
//	$info= str_replace("\"","`",$info);
//	$info= str_replace("\'","`",$info);
//	$info = str_replace('','/'/'',$info);
?>
<link rel="stylesheet" href="../css/content.css" type="text/css" />
<link rel="stylesheet" href="../css/ui/jquery.ui.datepicker.css" type="text/css" />
<script type="text/javascript">
	Ext.onReady(function(){
		var id = "<?php echo $id ?>";
		id = parseInt(id);
		var page_id = "<?php echo $page_id ?>";
		page_id = parseInt(page_id);
		Ext.Ajax.request({
			url:  'services/content.php',
			method: 'POST',
			params: {act : 'innit',
					 id : id,
					 page_id : page_id},
			success: function ( result, request ) {
				var arr = result.responseText;
				arr =arr.split('}#');
				for(var i=0;i<arr.length;i++){
					arr[i]=arr[i].replace('{','');
					arr[i]=arr[i].replace('}','');
					arr[i]=arr[i].replace(/\.-/g,'\n');
					arr[i]=arr[i].split('#');

				}
				$("#group").find("option[value="+ page_id + "]").attr("selected", "selected");
				$("#datepicker").val(arr[0][2]);
				$("#info").val(arr[0][3]);
			}
		});
        $( "#datepicker" ).datepicker({
			showOn: "button",
			buttonImage: "../images/calendar.gif",
			buttonImageOnly: true,
			dateFormat: 'yy/mm/dd'		
		});
		$('#editcontent').click(function(){
			var p=$('#group').val(); 
			var d=$('#datepicker').val();
			var i=$('#info').val().trim();
			Ext.Ajax.request({
				url:  'services/content.php',
				method: 'POST',
				params: {act :'edit_content',
						 id: id,
						 page_id: p,
						 date: d,
						 info: i},
				success: function ( result, request ){
					if(result.responseText == 1){
						alert("Thay đổi thành công");
						window.history.back();
					}
				},
				failure: function ( result, request ) {
					alert("Có lỗi khi kết nối cơ sở dữ liệu");
    			}
			})
		});
		$('#cancelcontent').click(function(){
			if(confirm("Bạn không muốn thay đổi?")){
				window.history.back();
			}
		});
	});
</script>
	<div id="wrapper">
		<form id="form" method="POST" action="">
			<fieldset>
				<legend>Edit Content</legend>				
					<div id="listpage">
						<label for="group">Group</label>
						<select name="group" id="group">
							<option value="1">HOME</option>
							<option value="2" >MENU</option>
							<option value="3" >PROMOTION</option>
							<option value="4" >COLLECTION</option>
							<option value="6">CONTACT</option>
						</select>
					</div>
                    <div>
                        <label for="date">Date</label>
    
                        <input id="datepicker" type="text" value= "" readonly="true" />
                    </div>
                    					
					<div id="message">
						<label for="message">Content</label>
						<textarea name="info" cols="50" rows="10" id="info"></textarea>
					</div>
					
					<div>
						<input type="button" id="editcontent" name="editcontent" value="Update Content" class="button" />
						<input type="button" id="cancelcontent" name="cancel" value="Cancel" class="button" />
					</div>
			</fieldset>
		</form>
	</div><!--end wrapper-->